package com.tgsoft.kdcloud.config;

import com.kingdee.bos.webapi.entity.AppCfg;
import com.kingdee.bos.webapi.entity.IdentifyInfo;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import com.kingdee.bos.webapi.utils.CfgUtil;
import com.tgsoft.kdcloud.properties.KingdeeProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(KingdeeProperties.class)
public class KingdeeCloudConfig {

    @Autowired
    private KingdeeProperties kingdeeProperties;

    // 查看 CfgUtil.getAppDefaultCfg(); 可以发现配置文件kdwebapi.properties必须放到根目录下。
    // 我这里就自定义 集合到 application.yml一个文件里了
    @Bean
    public K3CloudApi k3CloudApiGenerator(){


        IdentifyInfo iden=new IdentifyInfo();

        iden.setUserName(kingdeeProperties.getX_KDApi_UserName());
        iden.setAppId(kingdeeProperties.getX_KDApi_AppID());
        iden.setdCID(kingdeeProperties.getX_KDApi_AcctID());
        iden.setAppSecret(kingdeeProperties.getX_KDApi_AppSec());
        iden.setlCID(kingdeeProperties.getX_KDApi_LCID());
        iden.setServerUrl(kingdeeProperties.getX_KDApi_ServerUrl());


//        iden.setUserName("金蝶");
//        iden.setAppId("276359_R63q1/ss5rA/24+IQ/WMU9wrUKx80DqF");
//        iden.setdCID("6625e41c73f9d4");
//        iden.setAppSecret("cf887aa591a64d08aa8673afc1b8a748");
//        iden.setlCID(2052);
//        iden.setServerUrl("http://222.82.221.18:8099/K3Cloud/");

        return new K3CloudApi(iden);

    }


/**** https://vip.kingdee.com/article/486564927117971200?productLineId=1&lang=zh-CN
 private void loginByAppSecret() {
        AppCfg cfg = CfgUtil.getAppDefaultCfg();
        IdentifyInfo identifyInfo = new IdentifyInfo();
        identifyInfo.copyPropertiesToAppCfg(cfg);
        Object[] loginInfo = {identifyInfo.getdCID(), identifyInfo.getUserName(), identifyInfo.getAppId(),
                identifyInfo.getAppSecret(), getLanguageCode()};
        try {
            String execute = k3CloudApi.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.LoginByAppSecret", loginInfo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }*/



}